package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:此类归还书籍操作
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2024-01-03  09:08
 */
public class ReturnOpreation implements IOpreation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入您归还的书籍名称：");
        String name = scanner.nextLine();
        int pos = -1;
        int currentSize = bookList.getUsedSize();
        for(int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                book.setBorrowed(false);
                System.out.println("恭喜您，归还成功！");
                return;
            }
        }
        System.out.println("您归还的图书不存在，请重新选择！");
    }
}
